import { useState } from "react";
/**
 * 通用useReducer函数
 * @param {*} reducer reducer函数，标准格式
 * @param {*} initialState 初始状态
 * @returns 
 */
export default function  useReducer(reducer,initialState) {
  const [state, setState] = useState(initialState)
  const dispatch = (action)=>{
    const newState = reducer(state,action)
    setState(newState)
  }
  return [
    state,
    dispatch
  ]

}